package com.tycmc.signelectroniccontracts.tools.net;


import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/10/25 0025.
 */

public class RequestAction {
    //content-type类型
    public  String APPLICATIONJSON = "application/json";
    public  String APPLICATIONURLENCODED = "application/x-www-form-urlencoded";
    public Map<String, Object> requestMap;//请求body
    public Map<String, String> headerMap;//封装header
    public String contentType = APPLICATIONJSON;//请求type


    public String netUrl;//网络请求地址字段；

    public RequestAction(String netUrl) {
        this.netUrl = netUrl;
        requestMap = new HashMap<>();
        headerMap = new HashMap<>();
    }

    //动态设置content-type类型
    public RequestAction setContentType(String contentType) {
        this.contentType = contentType;
        return this;
    }

    /**
     * 添加请求body
     *
     * @param str
     * @param object
     * @return
     */
    public RequestAction putBody(String str, Object object) {
        requestMap.put(str, object);
        return this;
    }

    /**
     * 设置请求header
     *
     * @param key
     * @param name
     * @return
     */
    public RequestAction putHeader(String key, String name) {
        headerMap.put(key, name);
        return this;
    }

    /**
     * 批量添加请求body
     *
     * @param map
     * @return
     */
    public RequestAction putBodyAll(Map<String, Object> map) {
        requestMap.putAll(map);
        return this;
    }

    /**
     * 批量添加header
     *
     * @param map
     * @return
     */
    public RequestAction putHeaderAll(Map<String, String> map) {
        headerMap.putAll(map);
        return this;
    }
}
